package at.fhj.itm10.ticketmaster.dao;

import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * @author 	Kevin Reinmueller
 * @since	January 2013
 * 
 * Adapted Mr. Teiniker`s script
 */

public abstract class AbstractDAOTestBase {

	private SqlProcessor sqlProcessor = new SqlProcessor();
	
	/**
	 * Execute a SQL script file.
	 * 
	 * @throws IOException
	 * @throws ClassNotFoundException
	 * @throws SQLException
	 */
	protected void executeSqlScript(String sqlFile) {
		sqlProcessor.executeSqlScript(sqlFile);
	}
	
	/**
	 * get new connection
	 * @return Connection
	 * @throws ClassNotFoundException
	 * @throws SQLException
	 */
	protected Connection getConnection() throws ClassNotFoundException, SQLException {
	    return sqlProcessor.getConnection();
	}
	
	/**
	 * SQL transaction begin
	 * @param c
	 * @throws SQLException
	 */
    protected void txBegin(Connection c) throws SQLException {
        c.setAutoCommit(false);
    }

    /**
     * SQL transaction commit
     * @param c
     * @throws SQLException
     */
    protected void txCommit(Connection c) throws SQLException {
        c.commit();
        c.setAutoCommit(true);
    }

    /**
     * SQL transaction rollback
     * @param c
     * @throws SQLException
     */
    protected void txRollback(Connection c) throws SQLException {
        c.rollback();
        c.setAutoCommit(true);
    }

}
